package com.alisls.demo.springcloud.service.user.web.employee;

import com.alisls.demo.springcloud.common.model.dto.DataResult;
import com.alisls.demo.springcloud.common.model.dto.Result;
import com.alisls.demo.springcloud.service.user.dto.employee.EmployeeDTO;
import com.alisls.demo.springcloud.service.user.service.employee.EmployeeService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 员工管理
 *
 * @author Ke Wang
 * @date 2020/10/30
 */
@Api(tags = "员工管理")
@RestController
@RequestMapping("/employee")
@DefaultProperties(defaultFallback = "defaultMethodFallback")
@AllArgsConstructor
@Log4j2
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    /**
     * 根据员工工号查询员工
     * @param employeeNo
     * @return
     */
    @ApiOperation(value = "查询员工", notes = "根据员工工号查询员工")
    @GetMapping("/getByEmployeeNo/{employeeNo}")
    public Result getByEmployeeNo(@PathVariable String employeeNo) {
        EmployeeDTO employeeDTO = employeeService.getByEmployeeNo(employeeNo);
        return DataResult.ofSuccess(employeeDTO);
    }

    /**
     * 保存员工
     */
    @ApiOperation(value = "保存员工", notes = "保存员工信息")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid EmployeeDTO employeeDTO) {
        employeeDTO = employeeService.save(employeeDTO);
        return DataResult.ofSuccess(employeeDTO);
    }

}
